//
//  AY_BookSubDetailCell.m
//  AiYue
//
//  Created by boWen on 2023/10/25.
//

#import "AY_BookSubDetailCell.h"

@interface AY_BookSubDetailCell ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角

@property (strong,nonatomic) UIImageView * bookImgView;
@property (strong,nonatomic) UILabel * bookTitleLbl;
@property (strong,nonatomic) UILabel * bookSubTitleLbl;
@property (strong,nonatomic) UILabel * authorLabel;//作者
@property (strong,nonatomic) UILabel *tipLabel;
@end

@implementation AY_BookSubDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = COLOR_Bg;
        
        self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
        [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self.contentView);
        }];
        
        self.bookImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.bg_View];
        [self.bookImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(YNUM(93));
            make.width.mas_equalTo(YNUM(70));
            make.left.equalTo(self.bg_View).offset(YNUM(16));
            make.top.equalTo(self.bg_View).offset(YNUM(10));
        }];
        
        self.tipLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(10) andLines:1 andRadius:0 andAddSubView:self.bookImgView];
        self.tipLabel.layer.masksToBounds = NO;
        self.tipLabel.textAlignment = NSTextAlignmentCenter;
        [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.equalTo(self.bookImgView);
            make.width.mas_equalTo(YNUM(28));
            make.height.mas_equalTo(YNUM(16));
        }];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(28), YNUM(16)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(YNUM(4), YNUM(4))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.tipLabel.bounds;
        maskLayer.path = maskPath.CGPath;
        self.tipLabel.layer.mask = maskLayer;
        
        self.bookTitleLbl = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
        [self.bookTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bookImgView.mas_top);
            make.left.equalTo(self.bookImgView.mas_right).offset(YNUM(12));
            make.right.equalTo(self.bg_View.mas_right).offset(YNUM(-16));
            make.height.mas_equalTo(YNUM(24));
        }];

        self.bookSubTitleLbl = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#999999") andBgColor:nil andFont:YFont(12) andLines:2 andRadius:0 andAddSubView:self.bg_View];
        [self.bookSubTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bookTitleLbl.mas_bottom).offset(YNUM(6));
            make.left.equalTo(self.bookTitleLbl.mas_left);
            make.right.equalTo(self.bg_View.mas_right).offset(YNUM(-14));
        }];

        self.authorLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#999999") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
        [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bookImgView.mas_bottom);
            make.left.equalTo(self.bookTitleLbl.mas_left);
            make.right.equalTo(self.bg_View.mas_right).offset(YNUM(-14));
            make.height.mas_equalTo(YNUM(20));
        }];
    }
    return self;
}


- (void)setBookModel:(BookModel *)bookModel {
    _bookModel = bookModel;
    [self.bookImgView sd_setImageWithURL:[NSURL URLWithString:kStringUtils(_bookModel.coverImg)] placeholderImage:YImage(@"placeholderImage")];
    self.bookTitleLbl.text = kStringUtils(_bookModel.title);
    self.bookSubTitleLbl.text = kStringUtils(_bookModel.info);
//    self.authorLabel.text = kStringUtils(_bookModel.author);
    self.authorLabel.text = [NSString stringWithFormat:@"%@・%@・%@章",kStringUtils(_bookModel.author), kStringUtils(_bookModel.categoryName), kStringUtils(_bookModel.chapterNum)];
    [AYTool setBookStatusWithStatus:_bookModel.status andLabel:self.tipLabel];
}


@end
